﻿using System;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;

namespace StockSystem.Migrations
{
    public partial class addOutStock : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "SS_OutStockSummary",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    OutStockCode = table.Column<string>(nullable: false),
                    CustomerId = table.Column<int>(nullable: false),
                    OperatingUser = table.Column<string>(nullable: false),
                    OperatingTime = table.Column<DateTime>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SS_OutStockSummary", x => x.Id);
                    table.ForeignKey(
                        name: "FK_SS_OutStockSummary_SS_Customer_CustomerId",
                        column: x => x.CustomerId,
                        principalTable: "SS_Customer",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "SS_OutStockDetail",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    OutStockSummaryId = table.Column<int>(nullable: false),
                    GoodsId = table.Column<int>(nullable: false),
                    OutStockAmount = table.Column<int>(nullable: false),
                    OutStockPrice = table.Column<decimal>(nullable: false),
                    OutStockSumPrice = table.Column<decimal>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SS_OutStockDetail", x => x.Id);
                    table.ForeignKey(
                        name: "FK_SS_OutStockDetail_SS_Goods_GoodsId",
                        column: x => x.GoodsId,
                        principalTable: "SS_Goods",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_SS_OutStockDetail_SS_OutStockSummary_OutStockSummaryId",
                        column: x => x.OutStockSummaryId,
                        principalTable: "SS_OutStockSummary",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_SS_OutStockDetail_GoodsId",
                table: "SS_OutStockDetail",
                column: "GoodsId");

            migrationBuilder.CreateIndex(
                name: "IX_SS_OutStockDetail_OutStockSummaryId",
                table: "SS_OutStockDetail",
                column: "OutStockSummaryId");

            migrationBuilder.CreateIndex(
                name: "IX_SS_OutStockSummary_CustomerId",
                table: "SS_OutStockSummary",
                column: "CustomerId");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "SS_OutStockDetail");

            migrationBuilder.DropTable(
                name: "SS_OutStockSummary");
        }
    }
}
